package LeetcodeTest_two;
//平均值大于阈值的子数组

import java.util.*;

public class numOfSubarrays
{
    public static void main(String[] args)
    {
        int []arr={11,13,17,23,29,31,7,5,2,3};
        int k=3;
        int threshold=5;
        int answer=solution.numOfSubarrays(arr,k,threshold);
        System.out.println(answer);
    }
}
class solution
{
    public static int numOfSubarrays(int[] arr, int k, int threshold)
    {
        int answer;
        double average;
        int i,j;
        answer=i=j=0;
        average=0;
        for(i=0;i<arr.length-k+1;i++)
        {
            if(i==0)
                for(j=i;j<k+i;j++)
                    average+=arr[j];
            else
                average=average-arr[i-1]+arr[i+k-1];
            if(average/k>=threshold)
                answer++;
        }
        return answer;
    }

}